import { observable, action, computed } from 'mobx';
import Cookies from 'js-cookie';

class GlobalStore {
    @observable globalXHRCount = 0;
    @observable isLogon = false;
    err;

    @computed
    get isShowGlobalLoading() {
        return this.globalXHRCount > 0;
    }

    @action
    setVal(key, val) {
        if (!key) {
            return;
        }
        this[key] = val;
    }

    @action
    init() {
        this.globalXHRCount = 0;
        const userId = Cookies.get('client__user_id');
        if (userId) {
            this.isLogon = true;
            this.err = null;
        }
    }

}

export default new GlobalStore();

